package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.system.domain.TCompany;
import com.ruoyi.system.domain.TReason;
import com.ruoyi.system.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TReasonDetailMapper;
import com.ruoyi.system.domain.TReasonDetail;

import javax.annotation.Resource;

/**
 * 会计项目明细Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-03-17
 */
@Service
public class TReasonDetailServiceImpl implements ITReasonDetailService 
{
    @Autowired
    private TReasonDetailMapper tReasonDetailMapper;

    @Resource
    private ITReasonService itReasonService;

    @Resource
    private ITAccountService itAccountService;

    @Resource
    private ITCurrencyService itCurrencyService;

    @Resource
    private ITCompanyService itCompanyService;
    /**
     * 查询会计项目明细
     * 
     * @param rid 会计项目明细主键
     * @return 会计项目明细
     */
    @Override
    public TReasonDetail selectTReasonDetailByRid(Long rid)
    {
        return tReasonDetailMapper.selectTReasonDetailByRid(rid);
    }

    /**
     * 查询会计项目明细列表
     * 
     * @param tReasonDetail 会计项目明细
     * @return 会计项目明细
     */
    @Override
    public List<TReasonDetail> selectTReasonDetailList(TReasonDetail tReasonDetail)
    {
        List<TReasonDetail> tReasonDetailList=tReasonDetailMapper.selectTReasonDetailList(tReasonDetail);

        for(TReasonDetail i:tReasonDetailList){
            if(i.getOfReason()!=null){
                TReason tReason=itReasonService.selectTReasonByRid(i.getOfReason());
                i.setReasonName(tReason.getRname());
            }
            if(i.getOfCompany()!=null){
                TCompany tCompany=itCompanyService.selectTCompanyById(i.getOfCompany());
                i.setCompanyName(tCompany.getCompanyName());
            }
        }

        return tReasonDetailList;
    }

    /**
     * 新增会计项目明细
     * 
     * @param tReasonDetail 会计项目明细
     * @return 结果
     */
    @Override
    public int insertTReasonDetail(TReasonDetail tReasonDetail)
    {
        return tReasonDetailMapper.insertTReasonDetail(tReasonDetail);
    }

    /**
     * 修改会计项目明细
     * 
     * @param tReasonDetail 会计项目明细
     * @return 结果
     */
    @Override
    public int updateTReasonDetail(TReasonDetail tReasonDetail)
    {
        return tReasonDetailMapper.updateTReasonDetail(tReasonDetail);
    }

    /**
     * 批量删除会计项目明细
     * 
     * @param rids 需要删除的会计项目明细主键
     * @return 结果
     */
    @Override
    public int deleteTReasonDetailByRids(Long[] rids)
    {
        return tReasonDetailMapper.deleteTReasonDetailByRids(rids);
    }

    /**
     * 删除会计项目明细信息
     * 
     * @param rid 会计项目明细主键
     * @return 结果
     */
    @Override
    public int deleteTReasonDetailByRid(Long rid)
    {
        return tReasonDetailMapper.deleteTReasonDetailByRid(rid);
    }
}
